package org.lyq.erp.process.userrank.service;

import java.util.List;
import org.lyq.erp.process.userrank.mapper.TblWxUserrankMapper;
import org.lyq.erp.process.userrank.pojo.TblWxUserrank;
import org.lyq.erp.utils.format.FormatUtils;
import org.lyq.erp.utils.string.ObjectEmptyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TblWxUserrankServiceImpl implements TblWxUserrankService {
	@Autowired
	private TblWxUserrankMapper tblWxUserrankMapper;

	@Transactional
	public void insertUserrankSelective(TblWxUserrank tblWxUserrank) {
		if (ObjectEmptyUtils.isNotEmpty(tblWxUserrank.getRankDiscntStatimeView())
				&& ObjectEmptyUtils.isNotEmpty(tblWxUserrank.getRankDiscntEndtimeView())
				&& tblWxUserrank.getRankIstype().intValue() == 1) {
			tblWxUserrank.setRankDiscntStatime(Long
					.valueOf(FormatUtils.getDate(tblWxUserrank.getRankDiscntStatimeView(), "yyyy-MM-dd").getTime()));
			tblWxUserrank.setRankDiscntEndtime(Long
					.valueOf(FormatUtils.getDate(tblWxUserrank.getRankDiscntEndtimeView(), "yyyy-MM-dd").getTime()));
		}

		tblWxUserrank.setRankCreatetime(Long.valueOf(System.currentTimeMillis()));
		tblWxUserrank.setRankUpdatetime(Long.valueOf(System.currentTimeMillis()));
		tblWxUserrank.setRankStatus(Integer.valueOf(1));

		this.tblWxUserrankMapper.insertSelective(tblWxUserrank);
	}

	@Transactional
	public void updateUserrankByPrimaryKeySelective(TblWxUserrank tblWxUserrank) {
		if (ObjectEmptyUtils.isNotEmpty(tblWxUserrank.getRankDiscntStatimeView())
				&& ObjectEmptyUtils.isNotEmpty(tblWxUserrank.getRankDiscntEndtimeView())
				&& tblWxUserrank.getRankIstype().intValue() == 1) {
			tblWxUserrank.setRankDiscntStatime(Long
					.valueOf(FormatUtils.getDate(tblWxUserrank.getRankDiscntStatimeView(), "yyyy-MM-dd").getTime()));
			tblWxUserrank.setRankDiscntEndtime(Long
					.valueOf(FormatUtils.getDate(tblWxUserrank.getRankDiscntEndtimeView(), "yyyy-MM-dd").getTime()));
		}
		tblWxUserrank.setRankUpdatetime(Long.valueOf(System.currentTimeMillis()));
		tblWxUserrank.setRankStatus(Integer.valueOf(1));
		this.tblWxUserrankMapper.updateByPrimaryKeySelective(tblWxUserrank);
	}

	@Transactional
	public void deleteUserrankByPrimaryKey(Integer rankId) {
		this.tblWxUserrankMapper.deleteByPrimaryKey(rankId);
	}

	public TblWxUserrank selectUserrankByPrimaryKey(Integer rankId) {
		return this.tblWxUserrankMapper.selectByPrimaryKey(rankId);
	}

	public List<TblWxUserrank> list() {
		return this.tblWxUserrankMapper.allTblWxUserrank();
	}
}
